package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.ArchiveUsageStats;
import com.ruoyi.system.mapper.ArchiveUsageStatsMapper;
import com.ruoyi.system.service.ArchiveUsageStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 档案利用人次件次统计 Service 实现类
 * 具体实现业务逻辑，事务控制等
 *
 * @author [你的名字或团队名]
 */
@Service
public class ArchiveUsageStatsServiceImpl implements ArchiveUsageStatsService {

    @Autowired
    private ArchiveUsageStatsMapper statsMapper;

    @Override
    public List<ArchiveUsageStats> selectArchiveUsageStatsList(ArchiveUsageStats stats) {
        return statsMapper.selectArchiveUsageStatsList(stats);
    }

    @Override
    public ArchiveUsageStats selectArchiveUsageStatsById(Long id) {
        return statsMapper.selectArchiveUsageStatsById(id);
    }

    @Override
    public int insertArchiveUsageStats(ArchiveUsageStats stats) {
        return statsMapper.insertArchiveUsageStats(stats);
    }

    @Override
    public int updateArchiveUsageStats(ArchiveUsageStats stats) {
        return statsMapper.updateArchiveUsageStats(stats);
    }

    @Override
    public int deleteArchiveUsageStatsById(Long id) {
        return statsMapper.deleteArchiveUsageStatsById(id);
    }

    @Override
    public int deleteArchiveUsageStatsByIds(Long[] ids) {
        return statsMapper.deleteArchiveUsageStatsByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchSaveArchiveUsageStats(List<ArchiveUsageStats> list) {
        if (list.isEmpty()) {
            return 0;
        }

        statsMapper.deleteAll();
        // 2. 批量插入新数据
        return statsMapper.batchInsertArchiveUsageStats(list);
    }
}